import { filterObj } from '@/utils/util'
import { deleteAction, downFile, getAction } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import JEllipsis from '@/components/jeecg/JEllipsis'

export const activitiMixin = {
  components: {
    JEllipsis
  },
  data () {
    return {
      //token header
      tokenHeader: { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) },
      lcModa: {
        title: '',
        disabled: false,
        visible: false,
        formComponent: null,
        isNew: false
      }
    }
  },
  computed: {
    /*todo 所有的流程表单，组件化注册，在此维护*/
    allFormComponent: function () {
      return [


        {
          text: '资产领用',
          routeName: '@/views/activiti/form/ZcglRecipientsAdd',
          component: () => import(`@/views/activiti/form/ZcglRecipientsAdd`),
          businessTable: 'zcgl_recipients'
        },
        {
          text: '资产入库',
          routeName: '@/views/activiti/form/ZcglPutAssetAdd',
          component: () => import(`@/views/activiti/form/ZcglPutAssetAdd`),
          businessTable: 'zcgl_put_storage'
        },
        {
          text: '应收款拆费申请表单',
          routeName: '@/views/activiti/form/ReceivablesDemolitionFee',
          component: () => import(`@/views/activiti/form/ReceivablesDemolitionFee`),
          businessTable: 'zcgl_receivables_info'
        },
        {
          text: '应收款变更表单',
          routeName: '@/views/activiti/form/ReceivablesEdit',
          component: () => import(`@/views/activiti/form/ReceivablesEdit`),
          businessTable: 'zcgl_receivables_info'
        },
        {
          text: '合同生效表单',
          routeName: '@/views/activiti/form/LeaseContractTakeEffect',
          component: () => import(`@/views/activiti/form/LeaseContractTakeEffect`),
          businessTable: 'zcgl_lease_contract_info'
        },
        {
          text: '合同续签表单',
          routeName: '@/views/activiti/form/LeaseContractRenew',
          component: () => import(`@/views/activiti/form/LeaseContractRenew`),
          businessTable: 'zcgl_lease_contract_info'
        },
        {
          text: '合同变更表单',
          routeName: '@/views/activiti/form/LeaseContractModify',
          component: () => import(`@/views/activiti/form/LeaseContractModify`),
          businessTable: 'zcgl_lease_contract_info'
        },
        {
          text: '合同终止表单',
          routeName: '@/views/activiti/form/LeaseContractTermination',
          component: () => import(`@/views/activiti/form/LeaseContractTermination`),
          businessTable: 'zcgl_lease_contract_info'
        },
        {
          text: '资产变更表单',
          routeName: '@/views/activiti/form/AssetModify',
          component: () => import(`@/views/activiti/form/AssetModify`),
          businessTable: 'zcgl_asset_info'
        },
        {
          text: '资产新增表单',
          routeName: '@/views/activiti/form/AssetAdd',
          component: () => import(`@/views/activiti/form/AssetAdd`),
          businessTable: 'zcgl_asset_info'
        },
        {
          text: '退预存款表单',
          routeName: '@/views/activiti/form/CustomerBalanceRefund',
          component: () => import(`@/views/activiti/form/CustomerBalanceRefund`),
          businessTable: 'zcgl_customer_info'
        },
        {
          text: '固定资产生效表单',
          routeName: '@/views/activiti/form/AssetFixedTakeEffect',
          component: () => import(`@/views/activiti/form/AssetFixedTakeEffect`),
          businessTable: 'zcgl_asset_fixed'
        },
        {
          text: '固定资产借用表单',
          routeName: '@/views/activiti/form/AssetFixedModify',
          component: () => import(`@/views/activiti/form/AssetFixedModify`),
          businessTable: 'zcgl_asset_fixed_log'
        },
        {
          text: '固定资产归还表单',
          routeName: '@/views/activiti/form/AssetFixedReturnModify',
          component: () => import(`@/views/activiti/form/AssetFixedReturnModify`),
          businessTable: 'zcgl_asset_fixed_log'
        },
        {
          text: '固定资产维修表单',
          routeName: '@/views/activiti/form/AssetFixedMaintenance',
          component: () => import(`@/views/activiti/form/AssetFixedMaintenance`),
          businessTable: 'zcgl_asset_fixed_maintenance'
        },
        {
          text: '固定资产报废表单',
          routeName: '@/views/activiti/form/AssetFixedScrap',
          component: () => import(`@/views/activiti/form/AssetFixedScrap`),
          businessTable: 'zcgl_asset_fixed_maintenance'
        },
      ]
    },
    historicDetail: function () {
      return () => import(`@/views/activiti/historicDetail`)
    }
  },
  methods: {
    getFormComponent (routeName) {
      return _.find(this.allFormComponent, { routeName: routeName }) || {}
    },
    getFormComponentByTable (businessTable) {
      return _.find(this.allFormComponent, { businessTable: businessTable }) || {}
    },
    millsToTime (mills) {
      if (!mills) {
        return ''
      }
      let s = mills / 1000
      if (s < 60) {
        return s.toFixed(0) + ' 秒'
      }
      let m = s / 60
      if (m < 60) {
        return m.toFixed(0) + ' 分钟'
      }
      let h = m / 60
      if (h < 24) {
        return h.toFixed(0) + ' 小时'
      }
      let d = h / 24
      if (d < 30) {
        return d.toFixed(0) + ' 天'
      }
      let month = d / 30
      if (month < 12) {
        return month.toFixed(0) + ' 个月'
      }
      let year = month / 12
      return year.toFixed(0) + ' 年'

    },
    handleTableChange (pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadData();
    },
    toApplyListUrl(){


      this.$router.push({ path: '/activiti/applyList' })
    },
    processFormOk(){
      //在这里刷新
      this.loadData()
      this.lcModa.visible = false;
      this.toApplyListUrl()
    },
    processCreateCom(tableData, title, processStatus){

      // if (processStatus){processStatus === 2 ||
        if (processStatus === 1 || processStatus === 0){
          this.toApplyListUrl()
          return
        }

      // }
      this.lcModa.disabled = false
      this.lcModa.title = title
      this.lcModa.formComponent = this.getFormComponent(tableData.routeName).component
      this.lcModa.processData = tableData
      this.lcModa.isNew = true
      this.lcModa.visible = true
    }
  }

}